package com.hefu.virtuallife.ui;

import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;

import com.hefu.virtuallife.R;
import com.hefu.virtuallife.bean.SmartHomeBean;
import com.hefu.virtuallife.ui.adapter.RoomEqAdapter;
import com.hefu.virtuallife.utils.SmartDataUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SmartPersonalActivity extends AppCompatActivity implements View.OnClickListener{

    @BindView(R.id.img_back)
    ImageView back_btn;
    @BindView(R.id.lv_room)
    ListView lv_room;
    private String[] roomTypes = {"主卧", "次卧", "厨房", "客厅", "浴室", "书房"};
    private HashMap<String, List<String>> eq_map = new HashMap<>();
    private List<String> room_list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_smart_personal);

        ButterKnife.bind(this);
        initFullScreen();
        back_btn.setOnClickListener(this);

        initList();
    }

    public void initFullScreen() {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        });
        Window window = getWindow();
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //设置当前窗体为全屏显示
        window.setFlags(flag, flag);
    }

    private void initList() {

        for (String room : roomTypes){
            List<SmartHomeBean> list = SmartDataUtils.queryRoomEquip(room);
            if (null == list || list.size() == 0){
                continue;
            }

            List<String> list_eq = new ArrayList<>();
            for (SmartHomeBean bean : list){
                list_eq.add(bean.getName());
            }
            room_list.add(room);
            eq_map.put(room,list_eq);
        }

        lv_room.setAdapter(new RoomEqAdapter(this, room_list, eq_map));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_back:
                finish();
                break;
            default:
                break;
        }
    }
}
